Namespace FuncionesString
    Public Module mdFuncionesString
        Public Function numeroCerosAdelante(ByVal i As Integer, ByVal caracteres As Integer) As String
            Dim k As Integer
            Dim aux As String
            If i.ToString.Length >= caracteres Then
                Return aux
            Else
                For k = caracteres - i.ToString.Length To caracteres
                    aux += "0"
                Next
                aux += i.ToString
                Return aux
            End If
        End Function
        Public Function stringCapitalizado(ByVal textoFuente As String) As String
            Dim s() As String = Split(textoFuente, " ")
            Dim i As Integer
            Dim aux As String
            For i = 0 To s.Length - 1
                If s(i).Length > 3 Then
                    aux += " " & s(i).Substring(0, 1).ToUpper & s(i).Substring(1).ToLower
                Else
                    aux += " " & s(i).Substring(0).ToLower
                End If
            Next
            Return aux.Trim
        End Function
        Public Function getNumeroATexto(ByVal decCantidad As Decimal) As String

            Dim cantidad As String

            Dim x As Decimal = decCantidad

            'Dim decimales As Decimal = decCantidad



            Dim c1 As Integer = 0

            Dim c2 As Integer = 0

            Dim d1 As Integer = 0

            Dim d2 As Integer = 0

            Dim l1 As String = ""

            Dim l2 As String = ""

            Dim l3 As String = ""

            Dim l4 As String = ""



            Dim n1 As Integer

            If x >= 1000 And x < 10000 Then

                n1 = x \ 1000

                'agregado por alirio por la aprox
                If ((n1 * 100) - x) <= 0.5 And ((n1 * 1000) - x) > 0 Then
                    n1 = n1 - 1
                End If

                x = x Mod 1000

                ' decimales = decimales Mod 1000

                Select Case n1

                    Case 1

                        l1 = "Mil "

                    Case 2

                        l1 = "Dosmil "

                    Case 3

                        l1 = "Tresmil "

                    Case 4

                        l1 = "Cuatromil "

                    Case 5

                        l1 = "Cincomil "

                    Case 6

                        l1 = "Seismil "

                    Case 7

                        l1 = "Sietemil "

                    Case 8

                        l1 = "Ochomil "

                    Case 9

                        l1 = "Nuevemil "

                End Select

            End If



            If x >= 100 And x < 1000 Then

                n1 = x \ 100

                'agregado por alirio por la aprox
                If ((n1 * 100) - x) <= 0.5 And ((n1 * 100) - x) > 0 Then
                    n1 = n1 - 1
                End If

                x = x Mod 100

                ' decimales = 

                Select Case n1

                    Case 1

                        If x = 0 Then

                            l2 = "cien"

                        Else

                            l2 = "ciento "

                        End If

                    Case 2

                        l2 = "doscientos "

                    Case 3

                        l2 = "trescientos "

                    Case 4

                        l2 = "cuatrocientos "

                    Case 5

                        l2 = "quinientos "

                    Case 6

                        l2 = "seiscientos "

                    Case 7

                        l2 = "setecientos "

                    Case 8

                        l2 = "ochocientos "

                    Case 9

                        l2 = "novecientos "

                End Select

            End If



            If x >= 10 And x < 100 Then

                c1 = 1

                n1 = x \ 10

                If ((n1 * 10) - x) <= 0.5 And ((n1 * 10) - x) > 0 Then
                    n1 = n1 - 1
                End If

                x = x Mod 10



                Select Case n1

                    Case 1

                        If x <> 0 Then

                            d1 = 1

                        End If

                        l3 = "diez "

                    Case 2

                        l3 = "veinte "

                    Case 3

                        l3 = "treinta "

                    Case 4

                        l3 = "cuarenta "

                    Case 5

                        l3 = "cincuenta "

                    Case 6

                        l3 = "sesenta "

                    Case 7

                        l3 = "setenta "

                    Case 8

                        l3 = "ochenta "

                    Case 9

                        l3 = "noventa "

                End Select

            End If



            If x >= 1 And x < 10 Then

                c2 = 1

                Dim y As Integer

                y = x.Truncate(x)

                x = x Mod 1

                Select Case y

                    Case 1

                        If d1 = 0 Then

                            l4 = "uno"

                        Else

                            d2 = 1

                            l4 = "once"

                        End If

                    Case 2

                        If d1 = 0 Then

                            l4 = "dos"

                        Else

                            d2 = 1

                            l4 = "doce"

                        End If

                    Case 3

                        If d1 = 0 Then

                            l4 = "tres"

                        Else

                            d2 = 1

                            l4 = "trece"

                        End If

                    Case 4

                        If d1 = 0 Then

                            l4 = "cuatro"

                        Else

                            d2 = 1

                            l4 = "catorce"

                        End If

                    Case 5

                        If d1 = 0 Then

                            l4 = "cinco"

                        Else

                            d2 = 1

                            l4 = "quince"

                        End If

                    Case 6

                        l4 = "seis "

                    Case 7

                        l4 = "siete "

                    Case 8

                        l4 = "ocho "

                    Case 9

                        l4 = "nueve "

                End Select

            End If

            If d1 = 0 And d2 = 0 Then

                If c1 = 1 And c2 = 1 Then

                    cantidad = l1 + l2 + l3 + "y " + l4

                Else

                    cantidad = l1 + l2 + l3 + l4

                End If

            Else

                If d1 = 1 And d2 = 0 Then

                    cantidad = l1 + l2 + l3 + "y " + l4

                Else

                    cantidad = l1 + l2 + l4

                End If

            End If

            If x > 0 Then

                x = CInt(x * 100)

                cantidad = cantidad.Trim & " " & CStr(x) & "/100"  '& getNumeroATexto(x) & " ctvs."

            End If

            Return cantidad

        End Function
    End Module
End Namespace
